package Demo02;
/*
 * 题目：打印出杨辉三角形（要求打印出10行如下图）
程序分析：
        1 
       1 1 
     1 2 1 
1 3 3 1 
 1 4 6 4 1 
1 5 10 10 5 1 
 */
public class zy33 {
    public static void main(String[] args) {
        int n = 10; 
        printYangHui(n);
    }
    public static void printYangHui(int n) {
        int[][] arr = new int[n][];
        for (int i = 0; i < n; i++) {
            arr[i] = new int[i + 1];
            arr[i][0] = arr[i][i] = 1;
            for (int j = 1; j < i; j++) {
                arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j];
            }
        }
        for (int[] row : arr) {
            for (int j = 0; j < n - row.length; j++) {
                System.out.print(" "); 
            }
            for (int j : row) {
                System.out.print(j + " ");
            }
            System.out.println();
        }
    }
}